home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9002 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: news.bridge.net!news
  2. From: David Byrden <100101.2547@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: To find the class of an object ??
  5. Date: 27 Feb 1996 21:54:13 GMT
  6. Organization: self-employed
  7. Message-ID: <4gvui5$fqs@news.bridge.net>
  8. References: <4gvel6$4vg@cf01>
  9. NNTP-Posting-Host: ppp-mia2-86.bridge.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14.  
  15.  
  16. Didier;
  17.  
  18.  
  19. >>>>
  20. >I have a class A and a class B. The class B inherit the class A.
  21. >I have too: A tab[MAX];
  22. >In tab, I put objets of class A or B.
  23.  
  24. >How compare two objects of tab to know if they are of the same class ??
  25. >and which class they belong to ??
  26. <<<<<
  27.  
  28.  
  29.  
  30.   There is no need to compare, I can answer the question already. All the 
  31. objects in "tab" are always of class A.
  32.  
  33.   When you assign a B to an A, the derived B objects gets "sliced" and 
  34. you lose the parts that were added in class B. Only the data members of 
  35. its base part will be assigned to the A.
  36.  
  37.   In a good design, a base class object has no knowlege of whether it is 
  38. alone or whether it is part of a derived class object, so there will be 
  39. no evidence that the assigned value was ever a B. 
  40.  
  41.   What you probably want is for "tab" to be an array of _pointers_ to A.
  42.  
  43.                          David
  44.  
  45.  
  46.  
  47.